import { createRouter, createWebHistory, type RouteRecordRaw } from 'vue-router'
import HomeView from '@/views/HomeView.vue'
import NProgress from "nprogress"
import 'nprogress/nprogress.css'
const routes: RouteRecordRaw[] = [
  {
    path: '/',
    name: 'home',
    component: HomeView,
    children: [
      {
        path: 'keji',
        name: 'keji',
        component: () => import('../components/HomeView/Article/KeJi.vue'),
        meta: { title: '科技', id: 1 }
      },
      {
        path: 'history',
        name: 'history',
        component: () => import('../components/HomeView/Article/History.vue'),
        meta: { title: '历史', id: 2 }
      },
      {
        path: 'yule',
        name: 'yule',
        component: () => import('../components/HomeView/Article/YuLe.vue'),
        meta: { title: '娱乐', id: 3 }
      },
      {
        path: 'junshi',
        name: 'junshi',
        component: () => import('../components/HomeView/Article/JunShi.vue'),
        meta: { title: '军事', id: 4 }
      }
    ],
    meta: { title: '首页' }
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('../views/LoginView.vue'),
    meta: { title: '登录' }
  },
  {
    path: '/my',
    name: 'my',
    component: () => import('../views/MineView.vue'),
    meta: { title: '我的' }
  },
  {
    path: '/news',
    name: 'news',
    component: () => import('../views/EditView.vue'),
    meta: { title: '编辑' }
  }
]
const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes
})

// 路由守卫
router.beforeEach((to, form, next) => {
  NProgress.start()
  next()
})

// 后置守卫
router.afterEach((to, from) => {
  NProgress.done()
  document.title = to.meta.title as string || '大事件'
})

export default router
